package com.twotiger.and.util;

import java.util.ArrayList;
import java.util.List;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnKeyListener;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.Display;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import app.twotiger.p2p.R;

import com.twotiger.and.Constants;
import com.twotiger.and.adapter.HomePopAdapter;
import com.twotiger.and.adapter.RechargeHFBankAdapter;
import com.twotiger.and.bean.Bank;
import com.twotiger.and.bean.ImageBean;

/**
 * 提示信息的管理
 */

public class PromptManager {

    private static MyOnClickListener clickListener;
    private static AlertDialog confirmAlertDialog;
    private static AlertDialog dialog;
    // 当测试阶段时true
    private static final boolean isShow = true;
    private static Dialog loadingDialog;

    /**
     * @param context
     * @方法名称:showNoNetWork
     * @描述: 没网情况, 可以跳转到设置
     * @备注：
     * @返回类型：void
     */
    public static void showNoNetWork(final Context context) {
        Builder builder = new Builder(context);
        builder.setIcon(R.drawable.twotiger)//
            .setTitle(R.string.app_name)//
            .setMessage("当前无网络").setPositiveButton("设置", new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // 跳转到系统的网络设置界面
                    try {
                        Intent intent = new Intent();
                        intent.setAction("android.settings.WIRELESS_SETTINGS");
                        intent.addCategory(Intent.CATEGORY_DEFAULT);
                        context.startActivity(intent);
                    } catch (Exception e) {
                        Intent mIntent = new Intent("/");
                        ComponentName comp = new ComponentName("com.android.settings",
                            "com.android.settings.WirelessSettings");
                        mIntent.setComponent(comp);
                        mIntent.setAction("android.intent.action.VIEW");
                        context.startActivity(mIntent);
                    }

                }
            }).setNegativeButton("知道了", null);

        AlertDialog dialog = builder.create();
        dialog.setCanceledOnTouchOutside(false);
        dialog.show();
    }

    public interface MyOnClickListener {
        void onPositiveBtClick();

        void onNegativeBtClick();
    }

    // 提供一个回调方法
    public static void setMyOnClickListener(MyOnClickListener listener) {
        clickListener = listener;
    }

    /**
     * 得到自定义的progressDialog
     * 
     * @param context
     * @param msg
     * @return
     */
    @SuppressLint("InflateParams")
    public static Dialog showLoadDataDialog(Context context, String msg) {

        if (context instanceof Activity && ((Activity) context).isFinishing()) {
            return null;
        }

        LayoutInflater inflater = LayoutInflater.from(context);
        View v = inflater.inflate(R.layout.loading_dialog, null);// 得到加载view
        LinearLayout layout = (LinearLayout) v.findViewById(R.id.dialog_view);// 加载布局
        // main.xml中的ImageView
        ImageView spaceshipImage = (ImageView) v.findViewById(R.id.img);
        TextView tipTextView = (TextView) v.findViewById(R.id.tipTextView);// 提示文字
        // 加载动画
        Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(context,
            R.anim.loading_animation);
        // 使用ImageView显示动画
        spaceshipImage.startAnimation(hyperspaceJumpAnimation);
        if (null != msg) {
            tipTextView.setText(msg);// 设置加载信息
        }
        loadingDialog = new Dialog(context, R.style.loading_dialog);

        loadingDialog.setCancelable(true);// 不可以用“返回键”取消
        loadingDialog.setCanceledOnTouchOutside(false);
        loadingDialog.setContentView(layout, new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));// 设置布局
        try {
            loadingDialog.show();
        } catch (Exception e) {
        }
        return loadingDialog;
    }

    public static AlertDialog showCustomDialog(Context context, String title, String message,
                                               String leftText, String rightText,
                                               View.OnClickListener leftOnClickListener,
                                               View.OnClickListener rightOnClickListener,
                                               boolean isVisible) {
        Builder builder = new Builder(context);
        View view = View.inflate(context, R.layout.dialog_layout, null);
        TextView dtitle = (TextView) view.findViewById(R.id.dialog_title);
        TextView dmessage = (TextView) view.findViewById(R.id.dialog_message);
        TextView dcancel = (TextView) view.findViewById(R.id.dialog_cancel);
        TextView dcommit = (TextView) view.findViewById(R.id.dialog_commit);
        if (isVisible) {
            dcommit.setVisibility(View.GONE);
        }
        dtitle.setText(title);
        dmessage.setText(message);
        dcancel.setText(leftText);
        dcommit.setText(rightText);

        dcancel.setOnClickListener((View.OnClickListener) leftOnClickListener);
        dcommit.setOnClickListener((View.OnClickListener) rightOnClickListener);
        AlertDialog dialog = builder.create();
        dialog.setCanceledOnTouchOutside(false);
        dialog.setView(view, 0, 0, 0, 0);
        return dialog;
    }

    public static void closeCustomDialog(AlertDialog dialog) {
        if (dialog.isShowing()) {
            dialog.cancel();
            dialog.dismiss();
        }
    }
    public static AlertDialog showSimpleDialog(Context context, String title, String message,
                                               String btText) {
        Builder builder = new Builder(context);
        View view = View.inflate(context, R.layout.simple_dialog_layout, null);
        TextView content = (TextView) view.findViewById(R.id.content);
        TextView dialog_title = (TextView) view.findViewById(R.id.dialog_title);
        LinearLayout dcommit = (LinearLayout) view.findViewById(R.id.dialog_commit_layout);
        TextView dcommittext = (TextView) view.findViewById(R.id.dialog_commit);
        content.setText(message);
        dialog_title.setText(title);
        dcommittext.setText(btText);

        final AlertDialog simpleDialog = builder.create();
        simpleDialog.setView(view, 0, 0, 0, 0);
        simpleDialog.setCanceledOnTouchOutside(false);
        dcommit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                simpleDialog.dismiss();
            }
        });
        simpleDialog.show();
        return simpleDialog;
    }

    public static AlertDialog showSimpleCustomDialog(Context context, String title, String message,
                                                     String btText,
                                                     View.OnClickListener btOnClickListener) {
        Builder builder = new Builder(context);
        View view = View.inflate(context, R.layout.simple_dialog_layout, null);
        TextView content = (TextView) view.findViewById(R.id.content);
        TextView dialog_title = (TextView) view.findViewById(R.id.dialog_title);
        TextView dcommit = (TextView) view.findViewById(R.id.dialog_commit);
        View dcommit_layout = view.findViewById(R.id.dialog_commit_layout);

        content.setText(message);
        dialog_title.setText(title);
        dcommit.setText(btText);

        AlertDialog simpleDialog = builder.create();
        simpleDialog.setView(view, 0, 0, 0, 0);
        simpleDialog.setCanceledOnTouchOutside(false);
        dcommit_layout.setOnClickListener(btOnClickListener);
        return simpleDialog;
    }

    public static AlertDialog showMessageDialog(Context context, String message) {
        Builder builder = new Builder(context);
        // 获取LayoutInflater对象
        LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        // 由layout文件创建一个View对象
        View layout = inflater.inflate(R.layout.toast_layout, null);

        TextView textView = (TextView) layout.findViewById(R.id.text0);
        textView.setText(message);

        AlertDialog simpleDialog = builder.create();
        simpleDialog.setView(layout, 0, 0, 0, 0);
        simpleDialog.setCanceledOnTouchOutside(true);
        return simpleDialog;
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public static AlertDialog showCallDialog(final Context context, final String mobile) {
        Builder builder = new Builder(context, R.style.NoBlackDialog);
        View view = View.inflate(context, R.layout.dialog_callphone_layout, null);
        TextView dcancel = (TextView) view.findViewById(R.id.dialog_cancel);
        TextView dcommit = (TextView) view.findViewById(R.id.dialog_commit);

        final AlertDialog calldialog = builder.create();
        calldialog.setView(view, 0, 0, 0, 0);
        dcancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                calldialog.dismiss();
            }
        });

        dcommit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                IntentUtil.CallPhone(context, mobile);
                calldialog.dismiss();
            }
        });

        return calldialog;
    }

    /**
     * @return
     * @方法名称:logOutDialog
     * @描述: TODO
     * @创建人：曹睿翔
     * @创建时间：2014年9月9日 上午11:15:05
     * @备注：
     * @返回类型：AlertDialog
     */
    public static AlertDialog logOutDialog(Context context, String title, String message,
                                           String commit, String cancel,
                                           final MyOnClickListener clickListener) {
        Builder builder = new Builder(context);
        View view = View.inflate(context, R.layout.dialog_layout, null);
        TextView dtitle = (TextView) view.findViewById(R.id.dialog_title);
        TextView dmessage = (TextView) view.findViewById(R.id.dialog_message);
        TextView dcancel = (TextView) view.findViewById(R.id.dialog_cancel);
        TextView dcommit = (TextView) view.findViewById(R.id.dialog_commit);

        dtitle.setText(title);
        dmessage.setText(message);
        dcommit.setText(commit);
        dcancel.setText(cancel);
        dcommit.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (clickListener != null)
                    clickListener.onPositiveBtClick();
            }
        });
        dcancel.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (clickListener != null)
                    clickListener.onNegativeBtClick();
            }
        });
        dialog = builder.create();
        dialog.setView(view, 0, 0, 0, 0);
        dialog.setCanceledOnTouchOutside(false);
        dialog.show();
        return dialog;
    }

    /**
     * @param context
     * @return
     * @方法名称:showDefaultDialog
     * @描述: 用于回调一个PositiveButton回调
     * @创建人：曹睿翔
     * @创建时间：2014年9月3日 上午10:23:39
     * @备注：
     * @返回类型：AlertDialog
     */
    public static AlertDialog showDefaultDialog(final Context context, final String dtitle,
                                                final String message, final String commit,
                                                final String cancel) {
        Builder builder = new Builder(context);
        View view = View.inflate(context, R.layout.dialog_layout, null);

        builder.setTitle(dtitle).setMessage(message)
            .setPositiveButton(commit, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (clickListener == null) {
                        return;
                    }
                    clickListener.onPositiveBtClick();

                }
            }).setNegativeButton(cancel, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (clickListener == null) {
                        return;
                    }
                    clickListener.onNegativeBtClick();
                }
            });
        AlertDialog dialog = builder.create();
        dialog.setCanceledOnTouchOutside(false);
        dialog.setView(view, 0, 0, 0, 0);
        dialog.setCanceledOnTouchOutside(false);
        dialog.show();
        return dialog;
    }

    /**
     * @param context
     * @param msg
     * @return
     * @方法名称:showConfirmAlert
     * @描述: 确定框, 用于禁止用户其他操作, closeConfirmAlert()用于关闭Dialog
     * @创建人：曹睿翔
     * @创建时间：2014年9月3日 上午10:25:08
     * @备注：
     * @返回类型：AlertDialog
     */
    public static AlertDialog showConfirmAlert(final Context context, String msg) {

        Builder builder = new Builder(context);
        builder.setTitle(R.string.app_name).setMessage(msg).setPositiveButton("确定", null);
        confirmAlertDialog = builder.create();
        confirmAlertDialog.setCanceledOnTouchOutside(false);
        confirmAlertDialog.show();
        return confirmAlertDialog;
    }

    /**
     * 创建dialog，显示信息，确认、取消两个按钮
     * 
     * @param context
     * @param text_above
     * @param btnleft
     * @param btnright
     * @param reChargeClickListener
     * @return
     */

    public static AlertDialog showMyAlert(final Context context, String text_above, String btnleft,
                                          String btnright,
                                          final ReChargeClickListener reChargeClickListener,
                                          boolean isShow) {

        if (context instanceof Activity && ((Activity) context).isFinishing()) {
            return null;
        }

        Builder builder = new Builder(context);
        View view = View.inflate(context, R.layout.dialog_layout_my, null);
        TextView tv_above = (TextView) view.findViewById(R.id.tv_above);
        tv_above.setText(text_above);
        Button btn_cancel = (Button) view.findViewById(R.id.btn_cancel);
        Button btn_confirm = (Button) view.findViewById(R.id.btn_confirm);
        if (isShow) {
            btn_confirm.setVisibility(View.VISIBLE);
        } else {
            btn_confirm.setVisibility(View.GONE);
        }
        btn_confirm.setText(btnleft);
        btn_cancel.setText(btnright);

        final AlertDialog dialog = builder.create();
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(true);
        dialog.show();

        /*
         * 将对话框的大小按屏幕大小的百分比设置
         */
        WindowManager m = ((Activity) context).getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = dialog.getWindow().getAttributes(); // 获取对话框当前的参数值
        p.width = (int) (d.getWidth() * 0.9); // 宽度设置为屏幕的0.65
        dialog.getWindow().setAttributes(p);

        dialog.getWindow().setContentView(view);
        btn_confirm.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                reChargeClickListener.onClickConfirm();
                dialog.dismiss();
            }
        });
        btn_cancel.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                reChargeClickListener.onClickCancel();
                dialog.dismiss();
            }
        });
        return dialog;
    }

    /**
     * 创建dialog，适用于项目整体跟web交互的地方，成功与否弹框提示
     * 
     * @param context
     * @param resid
     * @param text_above
     * @param text_below
     * @param btnleft
     * @param btnright
     * @param isShowCancel
     * @param reChargeClickListener
     * @return
     */
    public static AlertDialog showConfirmAlertCommon(final Context context,
                                                     int resid,
                                                     String text_above,
                                                     String text_below,
                                                     String btnleft,
                                                     String btnright,
                                                     boolean isShowCancel,
                                                     final ReChargeClickListener reChargeClickListener) {
        if (context instanceof Activity && ((Activity) context).isFinishing()) {
            return null;
        }

        Builder builder = new Builder(context);
        View view = View.inflate(context, R.layout.dialog_layout_tishi, null);
//        view.findViewById(R.id.iv_pic).setBackgroundResource(resid);
        TextView tv_above = (TextView) view.findViewById(R.id.tv_above);
        tv_above.setText(text_above);
        TextView tv_below = (TextView) view.findViewById(R.id.tv_below);
        tv_below.setText(text_below);
        Button btn_cancel = (Button) view.findViewById(R.id.btn_cancel);
        Button btn_confirm = (Button) view.findViewById(R.id.btn_confirm);
        btn_confirm.setText(btnleft);
        btn_cancel.setText(btnright);
        if (!isShowCancel) {
            btn_cancel.setVisibility(View.GONE);
        } else {
            btn_cancel.setVisibility(View.VISIBLE);
        }

        final AlertDialog dialog = builder.create();
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
        dialog.show();

        /*
         * 将对话框的大小按屏幕大小的百分比设置
         */
        WindowManager m = ((Activity) context).getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = dialog.getWindow().getAttributes(); // 获取对话框当前的参数值
        p.width = (int) (d.getWidth() * 0.9); // 宽度设置为屏幕的0.65
        dialog.getWindow().setAttributes(p);

        dialog.getWindow().setContentView(view);
        btn_confirm.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                reChargeClickListener.onClickConfirm();
                dialog.dismiss();
            }
        });
        btn_cancel.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                reChargeClickListener.onClickCancel();
                dialog.dismiss();
            }
        });
        return dialog;
    }

    /**
     * 充值、取现、绑卡成功失败的弹框提示
     * 
     * @param context
     * @param resid   图标
     * @param text_above   
     * @param text_below  
     * @param text_between  中间文字
     * @param btnleft  左边按钮文字
     * @param btnright   右边按钮文字
     * @param isShowLeftBtn  是否显示左边按钮
     * @param isShowBetweenText  是否显示中间文字
     * @param isShowBottomLayout  是否显示底部布局
     * @param reChargeClickListener  中间按钮点击回调
     * @param mClickListener  底部联系我们的按钮点击回调
     * @return
     */
    public static AlertDialog showAlertCommon(final Context context, int resid, String text_above,
                                              String text_below, String text_between,
                                              String btnleft, String btnright,
                                              boolean isShowLeftBtn, boolean isShowBetweenText,
                                              boolean isShowBottomLayout,
                                              final ReChargeClickListener reChargeClickListener,
                                              final ClickListener mClickListener) {
        if (context instanceof Activity && ((Activity) context).isFinishing()) {
            return null;
        }

        Builder builder = new Builder(context);
        View view = View.inflate(context, R.layout.dialog_layout_common, null);
//        view.findViewById(R.id.iv_pic).setBackgroundResource(resid);

        TextView tv_above = (TextView) view.findViewById(R.id.tv_above);
        TextView tv_below = (TextView) view.findViewById(R.id.tv_below);
        TextView tv_between = (TextView) view.findViewById(R.id.tv_between);
        Button btn_left = (Button) view.findViewById(R.id.btn_left);
        Button btn_right = (Button) view.findViewById(R.id.btn_right);
        LinearLayout ll_bottom = (LinearLayout) view.findViewById(R.id.ll_bottom);
        TextView tv_tele = (TextView) view.findViewById(R.id.tv_tele);
        TextView tv_qq = (TextView) view.findViewById(R.id.tv_qq);

        tv_above.setText(text_above);
        tv_below.setText(text_below);
        tv_between.setText(text_between);
        btn_left.setText(btnleft);
        btn_right.setText(btnright);
        if (!isShowLeftBtn) {
            btn_left.setVisibility(View.GONE);
        } else {
            btn_left.setVisibility(View.VISIBLE);
        }
        if (!isShowBetweenText) {
            tv_between.setVisibility(View.GONE);
        } else {
            tv_between.setVisibility(View.VISIBLE);
        }
        if (!isShowBottomLayout) {
            ll_bottom.setVisibility(View.GONE);
        } else {
            ll_bottom.setVisibility(View.VISIBLE);
        }

        final AlertDialog dialog = builder.create();
        dialog.setCanceledOnTouchOutside(false);
        dialog.setOnKeyListener(new OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                LogUtil.info(DialogInterface.class, "keyEvent : " + keyCode);
                if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
                    ((Activity) context).finish();
                }
                return false;
            }
        });
        dialog.show();

        /*
         * 将对话框的大小按屏幕大小的百分比设置
         */
        WindowManager m = ((Activity) context).getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = dialog.getWindow().getAttributes(); // 获取对话框当前的参数值
        p.width = (int) (d.getWidth() * 0.9); // 宽度设置为屏幕的0.65
        dialog.getWindow().setAttributes(p);

        dialog.getWindow().setContentView(view);
        btn_left.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                reChargeClickListener.onClickConfirm();
                dialog.dismiss();
            }
        });
        btn_right.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                reChargeClickListener.onClickCancel();
                dialog.dismiss();
            }
        });

        tv_tele.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                mClickListener.onClickLeft();
            }
        });
        tv_qq.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                mClickListener.onClickRight();
            }
        });
        return dialog;
    }
    
    /**
     * 充值、取现、绑卡成功失败的弹框提示
     * @param list 
     * @param mContext 
     * 
     * @return
     */
    public static AlertDialog showHomePop(Context mContext, final List<ImageBean> list) {
        if (mContext instanceof Activity && ((Activity) mContext).isFinishing()) {
            return null;
        }

        Builder builder = null;
        if(android.os.Build.VERSION.SDK_INT >= 19){
            builder = new Builder(mContext, AlertDialog.THEME_TRADITIONAL);
        }else{
            builder = new Builder(mContext);
        }
        final AlertDialog dialog = builder.create();
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(true);
        dialog.show();
        
        
        View view = View.inflate(mContext, R.layout.dialog_home_pop, null);
        
        TextView tv_finish = (TextView) view.findViewById(R.id.tv_finish);
        final ViewPager view_pager = (ViewPager) view.findViewById(R.id.view_pager);
        final LinearLayout ll_vp = (LinearLayout) view.findViewById(R.id.ll_vp);

        HomePopAdapter homePopAdapter = new HomePopAdapter(mContext, list,dialog);
        if (homePopAdapter != null) {
            view_pager.setAdapter(homePopAdapter);
        }
        ll_vp.removeAllViews();//下拉会重新请求banner图接口。所以将所有的小圆点移除
        
        for (int i = 0; i < list.size(); i++) {

            // 添加点了
            ImageView point = new ImageView(mContext);
            // 创建了布局的参数 全部都是包裹内容
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(-2, -2);
            params.leftMargin = 5;
            // 给ImageView 设置参数
            point.setLayoutParams(params);
            point.setImageResource(R.drawable.selectot_points);
            if (i == 0) {
                point.setEnabled(true);
            } else {
                point.setEnabled(false);
            }
            ll_vp.addView(point);
        }
        tv_finish.setOnClickListener(new View.OnClickListener() {
            
            @Override
            public void onClick(View arg0) {
                dialog.dismiss();
            }
        });
        view_pager.setOnPageChangeListener(new OnPageChangeListener() {
            
            @Override
            public void onPageSelected(int position) {
                if (list.size() > 0) {
                    for (int i = 0; i < list.size(); i++) {
                        ImageView point = (ImageView) ll_vp.getChildAt(i);
                        if(point != null){
                            if(i == position){
                                point.setEnabled(true);
                            }else {
                                point.setEnabled(false);
                            }
                        }
                    }
                }
            }
            
            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {
                
            }
            
            @Override
            public void onPageScrollStateChanged(int arg0) {
                
            }
        });

        /*
         * 将对话框的大小按屏幕大小的百分比设置
         */
        WindowManager m = ((Activity) mContext).getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = dialog.getWindow().getAttributes(); // 获取对话框当前的参数值
//        p.width = (int) (d.getWidth() * 0.9); // 宽度设置为屏幕的0.65
//        p.height = (int) (d.getHeight() * 0.7); // 宽度设置为屏幕的0.65
//        p.width = ViewUtils.dip2px(mContext, 300); 
//        p.height = ViewUtils.dip2px(mContext, 400);
        dialog.getWindow().setAttributes(p);
        dialog.getWindow().setContentView(view);
        return dialog;
    }

    /**
     * 创建dialog，
     * 
     * @return
     */
    public static AlertDialog showDebtAlert(final Context context, String text_above,
                                            String text_below) {
        if (context instanceof Activity && ((Activity) context).isFinishing()) {
            return null;
        }

        Builder builder = new Builder(context);
        View view = View.inflate(context, R.layout.dialog_layout_debt_tishi, null);
        TextView tv_above = (TextView) view.findViewById(R.id.tv_above);
        tv_above.setText(text_above);
        TextView tv_below = (TextView) view.findViewById(R.id.tv_below);
        tv_below.setText(text_below);

        final AlertDialog dialog = builder.create();
        dialog.setCanceledOnTouchOutside(true);
        dialog.setCancelable(true);
        dialog.show();

        /*
         * 将对话框的大小按屏幕大小的百分比设置
         */
        WindowManager m = ((Activity) context).getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = dialog.getWindow().getAttributes(); // 获取对话框当前的参数值
        p.width = (int) (d.getWidth() * 0.9); // 宽度设置为屏幕的0.65
        dialog.getWindow().setAttributes(p);

        dialog.getWindow().setContentView(view);
        return dialog;
    }

    /**
     * 创建dialog，
     * 
     * @return
     */
    public static AlertDialog showCurrentAlert(final Context context, String text_above,
                                               String text_below) {
        if (context instanceof Activity && ((Activity) context).isFinishing()) {
            return null;
        }

        Builder builder = new Builder(context);
        View view = View.inflate(context, R.layout.dialog_layout_current_tishi, null);
        TextView tv_above = (TextView) view.findViewById(R.id.tv_above);
        tv_above.setText(text_above);
        TextView tv_below = (TextView) view.findViewById(R.id.tv_below);
        tv_below.setText(text_below);

        final AlertDialog dialog = builder.create();
        dialog.setCanceledOnTouchOutside(true);
        dialog.setCancelable(true);
        dialog.show();

        /*
         * 将对话框的大小按屏幕大小的百分比设置
         */
        WindowManager m = ((Activity) context).getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = dialog.getWindow().getAttributes(); // 获取对话框当前的参数值
        p.width = (int) (d.getWidth() * 0.9); // 宽度设置为屏幕的0.65
        dialog.getWindow().setAttributes(p);

        dialog.getWindow().setContentView(view);
        return dialog;
    }

    /**
     * 创建dialog，
     * 
     * @return
     */
    public static AlertDialog showCurrentAlertHasBtn(final Context context,
                                                     String text_above,
                                                     String text_below,
                                                     String text_btn,
                                                     boolean isShow,
                                                     final ReChargeClickListener reChargeClickListener) {
        if (context instanceof Activity && ((Activity) context).isFinishing()) {
            return null;
        }

        Builder builder = new Builder(context);
        View view = View.inflate(context, R.layout.dialog_layout_current_tishi_hasbtn, null);
        TextView tv_above = (TextView) view.findViewById(R.id.tv_above);
        tv_above.setText(text_above);
        TextView tv_below = (TextView) view.findViewById(R.id.tv_below);
        tv_below.setText(text_below);
        Button btn_confirm = (Button) view.findViewById(R.id.btn_confirm);
        btn_confirm.setText(text_btn);

        LinearLayout ll_isshow = (LinearLayout) view.findViewById(R.id.ll_isshow);
        if (isShow) {
            ll_isshow.setVisibility(View.VISIBLE);
        } else {
            ll_isshow.setVisibility(View.GONE);
        }

        final AlertDialog dialog = builder.create();
        dialog.setCanceledOnTouchOutside(true);
        dialog.setCancelable(true);
        dialog.show();

        /*
         * 将对话框的大小按屏幕大小的百分比设置
         */
        WindowManager m = ((Activity) context).getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = dialog.getWindow().getAttributes(); // 获取对话框当前的参数值
        p.width = (int) (d.getWidth() * 0.9); // 宽度设置为屏幕的0.65
        dialog.getWindow().setAttributes(p);

        dialog.getWindow().setContentView(view);
        btn_confirm.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                reChargeClickListener.onClickConfirm();
                dialog.dismiss();
            }
        });
        return dialog;
    }

    /**
     * 创建dialog，
     * 
     * @return
     */
    public static AlertDialog showCouponAlertHasBtn(final Context context,
                                                    String text_above,
                                                    String text_below,
                                                    String text_btn_left,
                                                    String text_btn_right,
                                                    final ReChargeClickListener reChargeClickListener) {
        if (context instanceof Activity && ((Activity) context).isFinishing()) {
            return null;
        }

        Builder builder = new Builder(context);
        View view = View.inflate(context, R.layout.dialog_layout_coupon_tishi_hasbtn, null);

        TextView tv_above = (TextView) view.findViewById(R.id.tv_above);
        tv_above.setText(text_above);
        TextView tv_below = (TextView) view.findViewById(R.id.tv_below);
        tv_below.setText(text_below);
        Button btn_left = (Button) view.findViewById(R.id.btn_left);
        btn_left.setText(text_btn_left);
        Button btn_right = (Button) view.findViewById(R.id.btn_right);
        btn_right.setText(text_btn_right);

        final AlertDialog dialog = builder.create();
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
        dialog.show();
        /*
         * 将对话框的大小按屏幕大小的百分比设置
         */
        WindowManager m = ((Activity) context).getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = dialog.getWindow().getAttributes(); // 获取对话框当前的参数值
        p.width = (int) (d.getWidth() * 0.9); // 宽度设置为屏幕的0.65
        dialog.getWindow().setAttributes(p);

        dialog.getWindow().setContentView(view);
        btn_left.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                reChargeClickListener.onClickConfirm();
                dialog.dismiss();
            }
        });
        btn_right.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                reChargeClickListener.onClickCancel();
                dialog.dismiss();
            }
        });
        return dialog;
    }

    public static final String SUCCESS = "success";
    public static final String FAILURRE = "failure";

    public static AlertDialog showCurrentAlertCommon(final Context context,
                                                     int resid,
                                                     String text_above,
                                                     String text_below,
                                                     String btnleft,
                                                     String btnright,
                                                     boolean isShowCancel,
                                                     boolean isShowBottom,
                                                     String type,
                                                     String times,
                                                     final ReChargeClickListener reChargeClickListener) {
        if (context instanceof Activity && ((Activity) context).isFinishing()) {
            return null;
        }

        Builder builder = new Builder(context);
        View view = View.inflate(context, R.layout.dialog_layout_tishi, null);
//        view.findViewById(R.id.iv_pic).setBackgroundResource(resid);
        TextView tv_above = (TextView) view.findViewById(R.id.tv_above);
        tv_above.setText(text_above);
        TextView tv_below = (TextView) view.findViewById(R.id.tv_below);
        tv_below.setText(text_below);
        Button btn_cancel = (Button) view.findViewById(R.id.btn_cancel);
        Button btn_confirm = (Button) view.findViewById(R.id.btn_confirm);
        btn_confirm.setText(btnleft);
        btn_cancel.setText(btnright);
        if (!isShowCancel) {
            btn_cancel.setVisibility(View.GONE);
        } else {
            btn_cancel.setVisibility(View.VISIBLE);
        }
        LinearLayout ll_isshow = (LinearLayout) view.findViewById(R.id.ll_isshow);
        TextView tv_tips_1 = (TextView) view.findViewById(R.id.tv_tips_1);
        TextView tv_tips_4 = (TextView) view.findViewById(R.id.tv_tips_4);
        tv_tips_4.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (ViewUtils.isFastDoubleClick(v)) {
                    return;
                }
                IntentUtil.CallPhone(context, Constants.PHONE_NUM);
            }
        });
        if (isShowBottom) {
            ll_isshow.setVisibility(View.VISIBLE);
            if (SUCCESS.equals(type)) {
                tv_tips_1.setText("由于您操作过于频繁，处于安全考虑，您今日可转入次数还剩  " + times + " 次");
                tv_tips_4.setVisibility(View.GONE);
            } else if (FAILURRE.equals(type)) {
                tv_tips_1.setText("如有疑问，欢迎拨打客服电话：");
                tv_tips_4.setText("" + Constants.PHONE_NUM_FORMAT);
                tv_tips_4.setVisibility(View.VISIBLE);
            }
        } else {
            ll_isshow.setVisibility(View.GONE);
        }

        final AlertDialog dialog = builder.create();
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
        dialog.show();

        /*
         * 将对话框的大小按屏幕大小的百分比设置
         */
        WindowManager m = ((Activity) context).getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = dialog.getWindow().getAttributes(); // 获取对话框当前的参数值
        p.width = (int) (d.getWidth() * 0.9); // 宽度设置为屏幕的0.65
        dialog.getWindow().setAttributes(p);

        dialog.getWindow().setContentView(view);
        btn_confirm.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                reChargeClickListener.onClickConfirm();
                dialog.dismiss();
            }
        });
        btn_cancel.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                reChargeClickListener.onClickCancel();
                dialog.dismiss();
            }
        });
        return dialog;
    }

    /**
     * 银行卡无卡支付限制的弹窗
     * 
     * @param context
     * @param reChargeClickListener
     * @return
     */
    public static AlertDialog showBankLimitAlert(final Context context,
                                                 final ReChargeClickListener reChargeClickListener) {
        if (context instanceof Activity && ((Activity) context).isFinishing()) {
            return null;
        }

        Builder builder = new Builder(context);
        View view = View.inflate(context, R.layout.dialog_bank_limit, null);

        Button btn_left = (Button) view.findViewById(R.id.btn_left);
        Button btn_right = (Button) view.findViewById(R.id.btn_right);
        TextView tv_phone = (TextView) view.findViewById(R.id.tv_phone);
        tv_phone.setText(Constants.PHONE_NUM_FORMAT);
        tv_phone.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (ViewUtils.isFastDoubleClick(v)) {
                    return;
                }
                IntentUtil.CallPhone(context, Constants.PHONE_NUM);
            }
        });

        final AlertDialog dialog = builder.create();
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
        dialog.show();

        /*
         * 将对话框的大小按屏幕大小的百分比设置
         */
        WindowManager m = ((Activity) context).getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = dialog.getWindow().getAttributes(); // 获取对话框当前的参数值
        p.width = (int) (d.getWidth() * 0.9); // 宽度设置为屏幕的0.65
        dialog.getWindow().setAttributes(p);

        dialog.getWindow().setContentView(view);
        btn_left.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                reChargeClickListener.onClickConfirm();
                dialog.dismiss();
            }
        });
        btn_right.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                reChargeClickListener.onClickCancel();
                dialog.dismiss();
            }
        });
        return dialog;
    }
    /**
     * 解绑银行卡的弹窗
     * 
     * @param context
     * @param reChargeClickListener
     * @return
     */
    public static AlertDialog showUnbindBankAlert(final Context context,
                                                 final ReChargeClickListener reChargeClickListener) {
        if (context instanceof Activity && ((Activity) context).isFinishing()) {
            return null;
        }

        Builder builder = new Builder(context);
        View view = View.inflate(context, R.layout.dialog_unbind_bank, null);

        Button btn_right = (Button) view.findViewById(R.id.btn_right);
        TextView tv_phone = (TextView) view.findViewById(R.id.tv_phone);
        tv_phone.setText(Constants.PHONE_NUM_FORMAT);
        tv_phone.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (ViewUtils.isFastDoubleClick(v)) {
                    return;
                }
                IntentUtil.CallPhone(context, Constants.PHONE_NUM);
            }
        });

        final AlertDialog dialog = builder.create();
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
        dialog.show();

        /*
         * 将对话框的大小按屏幕大小的百分比设置
         */
        WindowManager m = ((Activity) context).getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = dialog.getWindow().getAttributes(); // 获取对话框当前的参数值
        p.width = (int) (d.getWidth() * 0.9); // 宽度设置为屏幕的0.65
        dialog.getWindow().setAttributes(p);

        dialog.getWindow().setContentView(view);
        btn_right.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                reChargeClickListener.onClickCancel();
                dialog.dismiss();
            }
        });
        return dialog;
    }
    
    /**
     * 联系在线客服的弹窗
     * 
     * @param context
     * @param reChargeClickListener
     * @return
     */
    public static AlertDialog showContactAlert(final Context context,
                                               String text_above,
                                               String btn_top_text,
                                               String btn_bottom_text,
                                               final ClickListener mClickListener, boolean isShow) {
        if (context instanceof Activity && ((Activity) context).isFinishing()) {
            return null;
        }

        Builder builder = new Builder(context);
        View view = View.inflate(context, R.layout.dialog_contact, null);
        
        TextView tv_above = (TextView) view.findViewById(R.id.tv_above);
        Button btn_top = (Button) view.findViewById(R.id.btn_top);
        Button btn_bottom = (Button) view.findViewById(R.id.btn_bottom);
        tv_above.setText(text_above);
        btn_top.setText(btn_top_text);
        btn_bottom.setText(btn_bottom_text);
        if(isShow){
            btn_bottom.setVisibility(View.VISIBLE);
        }else {
            btn_bottom.setVisibility(View.GONE);
        }

        final AlertDialog dialog = builder.create();
        dialog.setCanceledOnTouchOutside(true);
        dialog.setCancelable(true);
        dialog.show();

        /*
         * 将对话框的大小按屏幕大小的百分比设置
         */
        WindowManager m = ((Activity) context).getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = dialog.getWindow().getAttributes(); // 获取对话框当前的参数值
        p.width = (int) (d.getWidth() * 0.9); // 宽度设置为屏幕的0.65
        dialog.getWindow().setAttributes(p);

        dialog.getWindow().setContentView(view);
        btn_top.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                mClickListener.onClickLeft();
                dialog.dismiss();
            }
        }); 
        btn_bottom.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                mClickListener.onClickRight();
                dialog.dismiss();
            }
        });
        return dialog;
    }

    /**
     * 创建dialog，
     * 
     * @return
     */
    public static AlertDialog showDebtInvestAlert(final Context context, String text_below,
                                                  final ReChargeClickListener reChargeClickListener) {
        if (context instanceof Activity && ((Activity) context).isFinishing()) {
            return null;
        }

        Builder builder = new Builder(context);
        View view = View.inflate(context, R.layout.dialog_layout_debt_invest_tishi, null);
        TextView tv_below = (TextView) view.findViewById(R.id.tv_below);
        Button btn_confirm = (Button) view.findViewById(R.id.btn_confirm);
        tv_below.setText(text_below);

        final AlertDialog dialog = builder.create();
        dialog.setCanceledOnTouchOutside(true);
        dialog.setCancelable(true);
        dialog.show();

        /*
         * 将对话框的大小按屏幕大小的百分比设置
         */
        WindowManager m = ((Activity) context).getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = dialog.getWindow().getAttributes(); // 获取对话框当前的参数值
        p.width = (int) (d.getWidth() * 0.9); // 宽度设置为屏幕的0.65
        dialog.getWindow().setAttributes(p);

        dialog.getWindow().setContentView(view);

        btn_confirm.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                reChargeClickListener.onClickConfirm();
                dialog.dismiss();
            }
        });

        return dialog;
    }

    /**
     * 创建dialog，适用于充值成功，失败。账户余额不足等情况
     * 
     * @param context
     * @param resid
     * @param text_above
     * @param text_below
     * @param isShowCancel
     * @param reChargeClickListener
     * @return
     */
    public static AlertDialog showConfirmAlert2(final Context context, int resid,
                                                String text_above, String text_below,
                                                String btnleft, String btnright,
                                                boolean isShowCancel,
                                                final ReChargeClickListener reChargeClickListener) {
        if (context instanceof Activity && ((Activity) context).isFinishing()) {
            return null;
        }

        Builder builder = new Builder(context);
        View view = View.inflate(context, R.layout.dialog_layout_2, null);
//        view.findViewById(R.id.iv_pic).setBackgroundResource(resid);
        TextView tv_above = (TextView) view.findViewById(R.id.tv_above);
        tv_above.setText(text_above);
        TextView tv_below = (TextView) view.findViewById(R.id.tv_below);
        tv_below.setText(text_below);
        Button btn_cancel = (Button) view.findViewById(R.id.btn_cancel);
        Button btn_confirm = (Button) view.findViewById(R.id.btn_confirm);
        btn_confirm.setText(btnleft);
        btn_cancel.setText(btnright);
        if (!isShowCancel) {
            btn_cancel.setVisibility(View.GONE);
        } else {
            btn_cancel.setVisibility(View.VISIBLE);
        }

        final AlertDialog dialog = builder.create();
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();

        /*
         * 将对话框的大小按屏幕大小的百分比设置
         */
        WindowManager m = ((Activity) context).getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = dialog.getWindow().getAttributes(); // 获取对话框当前的参数值
        p.width = (int) (d.getWidth() * 0.9); // 宽度设置为屏幕的0.65
        dialog.getWindow().setAttributes(p);

        dialog.getWindow().setContentView(view);
        btn_confirm.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                reChargeClickListener.onClickConfirm();
                dialog.dismiss();
            }
        });
        btn_cancel.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                reChargeClickListener.onClickCancel();
                dialog.dismiss();
            }
        });
        return dialog;
    }


    /**
     * 创建dialog，适用于取现是否绑卡的提示框
     * 
     * @param context
     * @param isshow    true显示绑定体现卡的布局，false显示绑定快捷卡的布局
     * @param bit    银行卡的icon
     * @param bankname  银行卡名字
     * @param backnub   银行卡号
     * @return
     */
    public static AlertDialog showConfirmAlert4(final Context context, boolean isshow, Bitmap bit,
                                                String bankname, String backnub,
                                                final ReChargeClickListener mReChargeClickListener) {
        if (context instanceof Activity && ((Activity) context).isFinishing()) {
            return null;
        }

        Builder builder = new Builder(context);
        View view = View.inflate(context, R.layout.dialog_layout_cash, null);
        LinearLayout ll_ishow = (LinearLayout) view.findViewById(R.id.ll_ishow); //绑定提现卡布局
        LinearLayout ll_isshow2 = (LinearLayout) view.findViewById(R.id.ll_isshow2); //绑定快捷卡布局
        ImageView bankcard_icon = (ImageView) view.findViewById(R.id.bankcard_icon);
        TextView tv_bankname = (TextView) view.findViewById(R.id.tv_bankname);
        TextView tv_backnub = (TextView) view.findViewById(R.id.tv_backnub);

        if (isshow) { //表示要显示绑定提现卡布局
            ll_ishow.setVisibility(View.VISIBLE);
            ll_isshow2.setVisibility(View.GONE);
        } else {
            ll_ishow.setVisibility(View.GONE);
            ll_isshow2.setVisibility(View.VISIBLE);
            if (bit != null) {
                bankcard_icon.setBackgroundDrawable(new BitmapDrawable(bit));
            }
            tv_bankname.setText(bankname);
            tv_backnub.setText(backnub);
        }

        Button btn_confirm = (Button) view.findViewById(R.id.btn_confirm);

        final AlertDialog dialog = builder.create();
        dialog.setCanceledOnTouchOutside(false);
        dialog.setOnKeyListener(new OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                LogUtil.info(DialogInterface.class, "keyEvent : " + keyCode);
                if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
                    mReChargeClickListener.onClickCancel();
                }
                return false;
            }
        });
        dialog.show();

        /*
         * 将对话框的大小按屏幕大小的百分比设置
         */
        WindowManager m = ((Activity) context).getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = dialog.getWindow().getAttributes(); // 获取对话框当前的参数值
        p.width = (int) (d.getWidth() * 0.9); // 宽度设置为屏幕的0.65
        dialog.getWindow().setAttributes(p);

        dialog.getWindow().setContentView(view);

        btn_confirm.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                mReChargeClickListener.onClickConfirm();
                dialog.dismiss();
            }
        });
        return dialog;
    }

    /**
     * 
     * 
     * @param context
     * @param list
     * @param mReChargeClickListener
     * @return
     */
    public static AlertDialog showConfirmAlertCharge(final Context context,
                                                     ArrayList<Bank> list,
                                                     final ReChargeClickListener mReChargeClickListener) {
        if (context instanceof Activity && ((Activity) context).isFinishing()) {
            return null;
        }

        Builder builder = new Builder(context);
        View view = View.inflate(context, R.layout.dialog_layout_recharge_alert, null);
        GridView gv_hf_bank = (GridView) view.findViewById(R.id.gv_hf_bank);
        Button btn_confirm = (Button) view.findViewById(R.id.btn_confirm);

        gv_hf_bank.setAdapter(new RechargeHFBankAdapter(context, list));

        final AlertDialog dialog = builder.create();
        dialog.setCanceledOnTouchOutside(false);
        dialog.show();

        /*
         * 将对话框的大小按屏幕大小的百分比设置
         */
        WindowManager m = ((Activity) context).getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = dialog.getWindow().getAttributes(); // 获取对话框当前的参数值
        p.width = (int) (d.getWidth() * 0.9); // 宽度设置为屏幕的0.65
        dialog.getWindow().setAttributes(p);

        dialog.getWindow().setContentView(view);
        btn_confirm.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                mReChargeClickListener.onClickConfirm();
                dialog.dismiss();
            }
        });
        return dialog;
    }

    /**
     * 
     * 
     * @param context
     * @param list
     * @param mReChargeClickListener
     * @return
     */
    public static AlertDialog showConfirmAlertChargeUpgrade(final Context context,
                                                            final ReChargeClickListener mReChargeClickListener) {
        if (context instanceof Activity && ((Activity) context).isFinishing()) {
            return null;
        }

        Builder builder = new Builder(context);
        View view = View.inflate(context, R.layout.dialog_layout_recharge_alert2, null);
        Button btn_confirm = (Button) view.findViewById(R.id.btn_confirm);

        final AlertDialog dialog = builder.create();
        dialog.setCanceledOnTouchOutside(false);
        dialog.show();

        /*
         * 将对话框的大小按屏幕大小的百分比设置
         */
        WindowManager m = ((Activity) context).getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = dialog.getWindow().getAttributes(); // 获取对话框当前的参数值
        p.width = (int) (d.getWidth() * 0.9); // 宽度设置为屏幕的0.65
        dialog.getWindow().setAttributes(p);

        dialog.getWindow().setContentView(view);
        btn_confirm.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                mReChargeClickListener.onClickConfirm();
                dialog.dismiss();
            }
        });
        return dialog;
    }

    /**
     * 弹窗的按钮接口
     * @Description: TODO(这里描述这个类的作用) 
     * @Author gao
     * @Date 2016年3月10日 下午7:08:26
     */
    public interface ReChargeClickListener {
        void onClickConfirm();

        void onClickCancel();
    }

    /**
     * 弹窗的按钮接口
     * @Description: TODO(这里描述这个类的作用) 
     * @Author gao
     * @Date 2016年3月10日 下午7:08:26
     */
    public interface ClickListener {
        void onClickLeft();

        void onClickRight();
    }

    public static void closeConfirmAlert() {
        if (confirmAlertDialog != null && confirmAlertDialog.isShowing()) {
            confirmAlertDialog.dismiss();
        }
    }

    /**
     * @param context
     * @param msg
     * @方法名称:showToastTest
     * @描述: 测试用 在正式投入市场：删
     * @创建人：曹睿翔
     * @创建时间：2014年9月3日 上午10:31:26
     * @备注：
     * @返回类型：void
     */
    public static void showToastTest(Context context, String msg) {
        if (isShow) {
            Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
        }
    }

    /**
     * @param context
     * @param msg
     * @方法名称:showToast
     * @描述: 唯一的吐丝
     * @创建人：曹睿翔
     * @创建时间：2014年9月3日 上午10:30:39
     * @备注：
     * @返回类型：void
     */
    public static void showToast(Context context, String msg) {
        Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
    }

    public static void showToast(Context context, int msgResId) {
        Toast.makeText(context, msgResId, Toast.LENGTH_SHORT).show();
    }

    public static void showCustomToast(Context context, CharSequence text) {

        if (context instanceof Activity && ((Activity) context).isFinishing()) {
            return;
        }

        Toast result = new Toast(context);

        // 获取LayoutInflater对象
        LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        // 由layout文件创建一个View对象
        View layout = inflater.inflate(R.layout.toast_layout, null);

        TextView textView = (TextView) layout.findViewById(R.id.text0);
        textView.setText(text);

        result.setView(layout);
        result.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
        result.setDuration(Toast.LENGTH_SHORT);
        result.show();
    }

    /**
     * 自定义toast 位置
     * 
     * 
     * @param context
     * @param msg
     */
    public static void showToastAtPostion(Context context, String msg) {
        Toast toast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }

    /**
     * 显示我的钱页面的dialog
     * 
     * @param context
     * @param msg
     * @return
     */
    public static Dialog showAccountDialog(Context context, String msg) {

        LayoutInflater inflater = LayoutInflater.from(context);
        View v = inflater.inflate(R.layout.loading_dialog, null);// 得到加载view
        LinearLayout layout = (LinearLayout) v.findViewById(R.id.dialog_view);// 加载布局
        // main.xml中的ImageView
        ImageView spaceshipImage = (ImageView) v.findViewById(R.id.img);
        TextView tipTextView = (TextView) v.findViewById(R.id.tipTextView);// 提示文字
        // 加载动画
        Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(context,
            R.anim.loading_animation);
        // 使用ImageView显示动画
        spaceshipImage.startAnimation(hyperspaceJumpAnimation);
        if (null != msg) {
            tipTextView.setText(msg);// 设置加载信息
        }
        Dialog accountDialog = new Dialog(context, R.style.loading_dialog);

        accountDialog.setCancelable(true);// 不可以用“返回键”取消
        accountDialog.setCanceledOnTouchOutside(false);
        accountDialog.setContentView(layout, new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));// 设置布局
        try {
            accountDialog.show();
        } catch (Exception e) {
        }
        return accountDialog;
    }

    /**
     * 关闭我的钱页面的dialog
     * 
     * @param Dialog
     * @return
     */
    public static void closeAccountDialog(Dialog accountDialog) {
        if (accountDialog != null && accountDialog.isShowing()) {
            accountDialog.dismiss();
        }
    }


    /**
     * 关闭正在加载数据的对话框
     */
    public static void closeLoadDataDialog() {
        if (loadingDialog != null && loadingDialog.isShowing()) {
            loadingDialog.dismiss();
        }
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
        if (confirmAlertDialog != null && confirmAlertDialog.isShowing()) {
            confirmAlertDialog.dismiss();
        }
    }

    public static void closeLoadDataDialog(Dialog loadingDialog) {
        if (loadingDialog != null && loadingDialog.isShowing()) {
            loadingDialog.dismiss();
        }
    }

    /**
     * 关闭正在加载数据的对话框
     */
    public static void closeWebviewLoadDataDialog() {
        if (loadingDialog != null && loadingDialog.isShowing()) {
            loadingDialog.dismiss();
            loadingDialog.cancel();
        }
    }
}
